﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microhard.Permission.Interface;
using Microhard.WarehouseInsp.Buz.Models;
using Microsoft.Practices.Unity;
using Microhard.WarehouseInsp.Buz.Interfaces;
using Microhard.Core;
using Microhard.Permission.MVCFilter;
using Microhard.WebUI.Models;
using Telerik.Web.Mvc;
using Microhard.Workflow;
using Microhard.WarehouseInsp.Buz.JHWorkflow;
using Microhard.Core.DBUtility;

namespace Microhard.WarehouseInsp.WebUI.Areas.WarehouseInsp.Controllers
{
    public class OutInPutApplyController : MicroHardBaseController<OutInPutApplyModel>
    {

        // GET: /WarehouseInsp/OutInPutApply/
        private IOutInputApply _apply = null;

        [Dependency]
        public IOutInputApply Apply
        {
            set
            {
                base._repository = _apply = value;
            }
            get
            {
                return _apply;
            }

        }

        [MVCFilterAtrForLogon()]
        public ActionResult GetSupProjectListByWarehouse(AttributeOfWindow aowModel, ScopeResult scope)
        {
            ISupProject project = IoC.Resolve<ISupProject>();
            project.scope = scope;
            var p = project.Query(null);
            aowModel.Data = new GridModel()
            {
                Data = p,
                Total = p.Count
            };
            return View(aowModel);


        }

        [MVCFilterAtrForLogon()]
        public ActionResult _ListPlgInWarehouseInfo(OutInPutApplyModel model, ScopeResult scope)
        {
            IOutIntPutWarehouse iiw = IoC.Resolve<IOutIntPutWarehouse>();
            var rtn = iiw.GetInRecordByProject(model.ProjectID);
            var userModel = new GridModel()
            {
                Data = rtn
            };

            return new JsonResult
            {
                Data = userModel,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet

            };
        }

        [StartJHWorkflowTransFilter("OutInPutApply", typeof(OutInPutTransDJImpl), typeof(JHGetConfig), Order = 4)]
        public override ActionResult StartC6Workflow(Guid identity, string approvers, ScopeResult scope, bool isWorkflowStarted)
        {
            return base.StartC6Workflow(identity, approvers, scope, isWorkflowStarted);
        }

        [MVCFilterAtrForLogon()]
        public override ActionResult DeleteSingle(List<OutInPutApplyModel> model, Core.DBUtility.ScopeResult scope)
        {
            IOutInputApply outInputApply = IoC.Resolve<IOutInputApply>();
            outInputApply.Delete(model[0]);
            return View();
        }

        public override ActionResult TempSaveCreate(OutInPutApplyModel model, Core.DBUtility.ScopeResult scope)
        {
            ViewData["PrjID"] = model.PrjID;
            return base.TempSaveCreate(model, scope);
        }


    }
}
